package org.jing.ext.compress;

import org.jing.core.lang.JingException;
import org.jing.core.util.GenericUtil;

import java.io.File;
import java.util.List;

/**
 * Description: <br>
 *
 * @author bks <br>
 * @since 2023-02-23 <br>
 */
public abstract class BaseDecompress {
    public static final int DEFAULT_BUFFER_SIZE = 1024 * 1024 * 10;

    protected int bufferSize = DEFAULT_BUFFER_SIZE;

    protected boolean deleteSrc = false;

    protected boolean logFlag = true;

    protected String password = null;

    public BaseDecompress() {}

    public BaseDecompress(BaseDecompress decompress) {
        setBufferSize(decompress.getBufferSize());
        setDeleteSrc(decompress.isDeleteSrc());
        setLogFlag(decompress.isLogFlag());
        setPassword(decompress.getPassword());
    }

    public int getBufferSize() {
        return bufferSize;
    }

    public void setBufferSize(int bufferSize) {
        this.bufferSize = bufferSize;
    }

    public boolean isDeleteSrc() {
        return deleteSrc;
    }

    public void setDeleteSrc(boolean deleteSrc) {
        this.deleteSrc = deleteSrc;
    }

    public boolean isLogFlag() {
        return logFlag;
    }

    public void setLogFlag(boolean logFlag) {
        this.logFlag = logFlag;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public abstract List<File> decompress(File srcFile, String outputDirectory);

    public List<File> decompress(File srcFile, File outputDirectory) {
        return decompress(srcFile, outputDirectory.getAbsolutePath());
    }

    public List<File> decompress(File srcFile) {
        return decompress(srcFile, srcFile.getParentFile().getAbsolutePath());
    }

    public List<File> decompress(String srcFilePath) {
        File srcFile = new File(srcFilePath);
        return decompress(srcFile, srcFile.getParentFile().getAbsolutePath());
    }

    public abstract List<File> decompressMultiple(File[] srcFiles, String outputDirectory);

    public List<File> decompressMultiple(File[] srcFiles, File outputDirectory) {
        return decompressMultiple(srcFiles, outputDirectory.getAbsolutePath());
    }

    public List<File> decompressMultiple(File[] srcFiles) {
        return decompressMultiple(srcFiles, srcFiles[0].getParentFile().getAbsolutePath());
    }

    public void checkMultiple(File[] srcFiles) {
        if (GenericUtil.count(srcFiles) <= 1) {
            throw new JingException("not multiple files");
        }
    }
}
